package cn.edu.scau.cmi.chenjieling.composite.transparent;

import java.util.ArrayList;
import java.util.List;

public class Leaf extends Component{
	private List<Component> childComponents = new ArrayList<>();
	private String name;
	public String t = this.name;
	public Leaf(String name) {
		this.name = name;
	}
	public void printStruct(String preStr) {
		 System.out.println(preStr + "+" + this.name);
		 t = preStr+"-"+this.name;
		 	if(this.childComponents != null){
	            preStr += "  ";
	            for(Component c : childComponents){
	                c.printStruct(preStr);
	            }
	        }
		 	t = preStr+"-"+this.name;
	}
	
	public void add(Component child) {
		childComponents.add(child);
	}
	public void remove(int index) {
		childComponents.remove(index);
	}
	public List<Component> getChild() {
		return childComponents;
	}
}
